package com.lysj.print.print.controller;

import com.lysj.admin.utils.spring.foundation.base.BaseController;
import com.lysj.admin.utils.spring.foundation.pagination.PageUtil;
import com.lysj.admin.utils.spring.foundation.pagination.PageVo;
import com.lysj.admin.utils.web.Resp;
import com.lysj.print.print.domain.PrintArea;
import com.lysj.print.print.feign.FoodFeign;
import com.lysj.print.print.service.PrintAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by drj on 2019-03-15 16:44:47
 * @description 打印区域控制层
 */
@Slf4j
@RestController
@RequestMapping("/print/print_area")
public class PrintAreaController extends BaseController<PrintArea> {

    @Resource
    private PrintAreaService printAreaService;

    @Override
    public PrintAreaService getService() {
        return printAreaService;
    }


    @Resource
    private FoodFeign foodFeign;

    @GetMapping("/list_rewrite")
    public Resp listRewrite(String storeId, PageVo pageVo) {
        Pageable pageable = PageUtil.initPage(pageVo);
        return new Resp().success(printAreaService.getRepository().findStoreAreaList(pageable, storeId));
    }


    @GetMapping("/select_item_rewrite")
    public Resp selectItemRewrite(String storeId) {
        return new Resp().success(printAreaService.getRepository().findByStoreId(storeId));
    }

    @Override
    public Resp logicalDel(String[] ids) {
        //调用foodFeign,清空打印区域对应的菜品列表的区域id
        foodFeign.foodAreaClean(ids[0]);
        return super.logicalDel(ids);
    }
}
